// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Platform, Text, View, Image, TouchableOpacity, ImageBackground, ScrollView, TextInput, InteractionManager, PermissionsAndroid, } from 'react-native';


// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';
import Icon from 'react-native-vector-icons/Ionicons';
import ImagePicker from 'react-native-image-crop-picker';
import RNFetchBlob from 'react-native-fetch-blob'

// antd 按需加载
import { Tabs, Toast, Portal, Picker, Checkbox } from '@ant-design/react-native';

// 引入 处理数据 所需文件
import { withdrawal } from '../../module/module.js'

// 引入样式
import Style from './style/style.js';

// 引入公用组件
import { Status, NavBar, CacheImage } from '../../components/index.js'

// 引入专用组件
import { } from './components'

// 引入工具包
import { } from '../../util/images.js';
import { press, pathHead, size, ScreenWidth, hotTextColor, path, initUser, FileUpload, defaultDataList, onEndReached, onRefresh, concatDataList, defaultPage } from '../../util/utils.js'

class Withdrawal extends Component {

  constructor(props) {
    super(props)
    this.state = {
    }
  }


  componentDidMount() {

  }

  withdrawal() {
    const { cv } = this
    if (!cv) {
      Toast.info('请输入提现cv', 1);
      return;
    }
    if (cv < 100) {
      Toast.info('提现cv不能少于100', 1);
      return;
    }
    if (cv > 5000) {
      Toast.info('提现cv不能少于100', 1);
      return;
    }
    this.loading = Toast.loading('请求中', 0)
    withdrawal({
      cv: cv._lastNativeText,
    }).then(res => {
      Portal.remove(this.loading)
      console.log(res, '设置成功')
      // console.log('login')
      Toast.info(res.message, 2);
    }).catch(error => {
      Portal.remove(this.loading)
      console.log(error, '失败的地方')
      Toast.info(error.message, 2);
    }).finally(() => {
      Portal.remove(this.loading)
    })
  }

  render() {
    return (
      <View style={Style.container}>
        <Status />
        <NavBar
          title="提现"
          back={true}
        />
        <ScrollView style={Style.content}>
          <View style={{
            padding: 15,
            backgroundColor: '#fff'
          }}
          >
            <View style={{
              flexDirection: 'row',
              alignItems: 'center',
              borderBottomWidth: 1,
              borderBottomColor: '#ececee',
              marginTop: 0,
            }}
            >
              <TextInput
                ref={(r) => this.cv = r}
                keyboardType="numeric"
                placeholder="请输入提现cv"
                placeholderTextColor="#c8c8ca"
                style={{
                  flex: 1,
                  fontSize: 16,
                  paddingVertical: 16,
                  borderWidth: 0,
                  paddingHorizontal: 5,
                  color: '#3e3e3e',
                }}
                underlineColorAndroid="transparent"
              />
            </View>
            <View style={{ padding: 15, }}>
              <TouchableOpacity
                onPress={() => {
                  this.withdrawal()
                }}
                style={{
                  paddingVertical: 14,
                  paddingHorizontal: 20,
                  backgroundColor: hotTextColor,
                  borderRadius: 6,
                  alignItems: 'center',
                  justifyContent: 'center',
                }}
              >
                <Text style={{ fontSize: size(28), color: '#fff', lineHeight: size(30), }}>提现</Text>
              </TouchableOpacity>
            </View>
          </View>
        </ScrollView>
      </View >
    );
  }
}


export default connect(({ user, token }) => ({
  user, token
}))(pureRender(Withdrawal))
